//
//  ChangePwdViewController.m
//  Weiweiyunshi
//
//  Created by 王译 on 17/2/6.
//  Copyright © 2017年 王译. All rights reserved.
//

#import "ChangePwdViewController.h"
#import "ChangePwdView.h"
#define URL @"http://210.72.239.121:8088/SSIL/ModifyUserPwd.do?userId=sunsiyuan&oldPwd=%@&newPwd=%@"
@interface ChangePwdViewController ()
{
    ChangePwdView *pwdView;
}
@end

@implementation ChangePwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改密码";
    pwdView = [[ChangePwdView alloc]init];
    self.view = pwdView;
    [pwdView.changeButton addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];
    // Do any additional setup after loading the view.
}

-(void)change:(id)sender{
    if ([pwdView.nowPwdTextField.text isEqualToString:pwdView.confirmPwdTextField.text]) {
        [self request];
    }else{
        [MBProgressHUD showErrorMessage:@"密码不一致"];
    }
}

-(void)request{
    NSString *urlStr = [NSString stringWithFormat:URL,pwdView.oldPwdTextField.text,pwdView.nowPwdTextField.text];
    [WYHttpRequest getWithURLString:urlStr parameters:nil success:^(id responseObject) {
        if ([responseObject[@"Code"] isEqualToString:@"1"]) {
            [MBProgressHUD showSuccessMessage:@"修改成功"];
        }else
        {
            [MBProgressHUD showErrorMessage:@"密码不正确"];
        }
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
